package com.dwin.dingnuo.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.dwin.dingnuo.R;


/**
 * 自定义UI Dialog
 */
public class DwinDialogV3 extends Dialog implements View.OnClickListener {

    private Context context;
    private TextView dialog_content;
    private TextView tv_confirm;
    private MyDialogListener listener;

    private String content;
    private String positiveTxt;
    private String negativeTxt;

    public DwinDialogV3 setContent(String content) {
        this.content = content;
        return this;
    }

    public DwinDialogV3 setPositiveTxt(String positiveTxt) {
        this.positiveTxt = positiveTxt;
        return this;
    }

    public interface MyDialogListener {
        void onClick(View view);
    }

    public DwinDialogV3(Context context) {
        super(context);
        this.context = context;
    }

    public DwinDialogV3(Context context, int style, MyDialogListener listener) {
        super(context, style);
        this.context = context;
        this.listener = listener;
    }

    //    style引用style样式  dialog_dwin_layout
    public DwinDialogV3(Context context, int style) {
        super(context, style);
    }

    public void setDialogListener(MyDialogListener listener) {
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_dwin_v3);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);

        dialog_content = findViewById(R.id.dialog_content);
        tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(this);
        if (content != null) {
            dialog_content.setText(content);
        }
        if (positiveTxt != null) {
            tv_confirm.setText(positiveTxt);
        }
    }

    @Override
    public void onClick(View v) {
        if (listener != null) {
            listener.onClick(v);
        }
    }

}
